package org.sy.lab.Java7并发编程实战.七定制并发类.八实现定制Lock类;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;

public class MyAbstractQueuedSynchronizer extends AbstractQueuedSynchronizer {
	private AtomicInteger state;
	public MyAbstractQueuedSynchronizer() {
		state = new AtomicInteger(0);
	}
	@Override
	protected boolean tryAcquire(int arg) {
		return state.compareAndSet(0, 1);
	}
	@Override
	protected boolean tryRelease(int arg) {
		return state.compareAndSet(1, 0);
	}
}
